/*
 * jQuery Watermark plugin
 * Version 0.9 (17-JUL-2009)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://mario.ec/projects/jqwatermark/
 * Copyright (c) 2009 Mario Estrada
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */

(function($){
  $.fn.watermark = function(text){
		
    return this.each(function(){
      var label_text = text === undefined ? $(this).attr('title') : $(this).attr('title');
      var watermark_container = $('<span class="watermark_container"></span>');
      var watermark_label = $('<span class="watermark">' + label_text + '</span>');
			
      $(this).wrap(watermark_container);

      checkVal($(this).val(), watermark_label, $(this));
			
      watermark_label.click(function(){
        $(this).next().focus();
      })

      $(this).before(watermark_label)
      .focus(function(){
        checkVal($(this).val(), watermark_label, $(this));
        watermark_label.addClass('watermark-out');
      })
      .blur(function(){
        checkVal($(this).val(), watermark_label, $(this));
        watermark_label.removeClass('watermark-out');
      })
      .keydown(function(e){
        $(watermark_label).hide();
      });
    });
  };
	
  var checkVal = function(val, elem, input){
    if(val == '') {$(elem).show();}
    else {$(elem).hide();}
  };
})(jQuery);